from database.db_handler import MysqlHander

class AttrV3:
    def __init__(self):
        self.db = MysqlHander("config.ini")
        pass

    def add_attr_data_temp(self, code, relation_new, data_title, data_date, data_url, data_site):
        info_type = 0
        insert = "insert into relation_data_03_temp (Fsrc_code, Fsrc_type, Frelation_id, Ftitle, Fdate, Furl, Fsite, Fstatus, Fcreate_time, Fmodify_time) values "
        insert += "('" + code + "', 0, " + str(relation_new) + ",'" + data_title + "','" + data_date + "','" + data_url + "','" + data_site + "',0, now(), now());"
        
        print(insert)
        try:
            #pass
            self.db.execute_not_safe(insert)
        except Exception as e:
            print(str(e))
            pass

    def add_attr_data(self, table, code, data_title, data_date, data_url, data_site):
        info_type = 0
        insert = "insert into " + table + " (Fsrc_code, Fsrc_type, Ftitle, Fdate, Furl, Fsite, Fcreate_time, Fmodify_time) values "
        insert += "('" + code + "', 0,'" + data_title + "','" + data_date + "','" + data_url + "','" + data_site + "', now(), now());"
        
        print(insert)
        try:
            #pass
            self.db.execute_not_safe(insert)
        except Exception as e:
            print(str(e))
            pass

    def get_table_name(self, relation):
        if relation == 3001:
            return "relation_data_03_tiaojia"
        elif relation == 3002:
            return "relation_data_03_chufa"
        elif relation == 3003:
            return "relation_data_03_susong"
        elif relation == 3004:
            return "relation_data_03_diaoyan"
        elif relation == 3005:
            return "relation_data_03_chanyelian"
        elif relation == 3006:
            return "relation_data_03_guanli"
        elif relation == 3007:
            return "relation_data_03_yeji"
        elif relation == 3999:
            return "relation_data_03_other"

        return ""